using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Wicresoft.SMS.Send
{
    public partial class Setting : Form
    {
        public Setting()
        {
            InitializeComponent();
        }

        private void Setting_Load(object sender, EventArgs e)
        {
            try
            {
                this.txtUrl.Text = ConfigManage.ProviderUrl;
                this.txtUsername.Text = ConfigManage.UserName;
                this.txtPwd.Text = ConfigManage.Password;
                CheckInput();
            }
            catch (Exception ex)
            {
                Logger.Exception("Setting.Setting_Load ", ex);
            }
            
        }


        private void CheckInput()
        {
            try
            {
                if (this.txtUsername.Text.Trim() == "" || this.txtPwd.Text.Trim() == "" || this.txtUrl.Text.Trim() == "")
                {
                    this.btnOK.Enabled = false;
                }
                else
                    this.btnOK.Enabled = true;
            }
            catch (Exception ex)
            {
                Logger.Exception("Setting.CheckInput ", ex);
            }
            
        }

        private void txtUrl_TextChanged(object sender, EventArgs e)
        {
            CheckInput();
        }

        private void txtUsername_TextChanged(object sender, EventArgs e)
        {
            CheckInput();
        }

        private void txtPwd_TextChanged(object sender, EventArgs e)
        {
            CheckInput();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                string url = this.txtUrl.Text.Trim();
                string user = this.txtUsername.Text.Trim();
                string pwd = this.txtPwd.Text.Trim();
                ConfigSaver.Save(url, user, pwd);
                this.Close();
            }
            catch (Exception ex)
            {
                 Logger.Exception("Setting.btnOk_Click ", ex);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}